<template>
  <div class="avue-top">
    <div class="top-bar__left">
      <div class="avue-breadcrumb"
           :class="[{ 'avue-breadcrumb--active': isCollapse }]"
           v-if="showCollapse">
        <i class="icon-navicon"
           @click="setCollapse"></i>
      </div>
    </div>
    <div class="top-bar__title">
      <div class="top-bar__item top-bar__item--show"
           v-if="showMenu">
        <top-menu></top-menu>
      </div>
      <span class="top-bar__item"
            v-if="showSearch">
        <top-search></top-search>
      </span>
    </div>
    <div class="top-bar__right">
      <el-dropdown class="noti-container" trigger="click" @command="handleCommand">
        <div class="noti-info">
          <img class="noti-img" src="@/assets/notification.png" alt="">
          <span class="noti-number">{{tiAlarm + missedAlarm}}</span>
        </div>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="0">
            图文报警 <span class="noti-number-b">{{tiAlarm}}</span>
          </el-dropdown-item>
          <el-dropdown-item divided command="1">
            漏接报警 <span class="noti-number-b">{{missedAlarm}}</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <el-tooltip v-if="showColor"
                  effect="dark"
                  :content="$t('navbar.color')"
                  placement="bottom">
        <div class="top-bar__item">
          <top-color></top-color>
        </div>
      </el-tooltip>
      <el-tooltip v-if="showDebug"
                  effect="dark"
                  :content="logsFlag?$t('navbar.bug'):logsLen+$t('navbar.bugs')"
                  placement="bottom">
        <div class="top-bar__item">
          <top-logs></top-logs>
        </div>
      </el-tooltip>
      <el-tooltip v-if="showLock"
                  effect="dark"
                  :content="$t('navbar.lock')"
                  placement="bottom">
        <div class="top-bar__item">
          <top-lock></top-lock>
        </div>
      </el-tooltip>
      <el-tooltip v-if="showTheme"
                  effect="dark"
                  :content="$t('navbar.theme')"
                  placement="bottom">
        <div class="top-bar__item top-bar__item--show">
          <top-theme></top-theme>
        </div>
      </el-tooltip>
      <el-tooltip v-if="showTranslation" effect="dark"
                  :content="$t('navbar.language')"
                  placement="bottom">
        <div class="top-bar__item top-bar__item--show">
          <top-lang></top-lang>
        </div>
      </el-tooltip>
      <el-tooltip v-if="showFullScren"
                  effect="dark"
                  :content="isFullScren?$t('navbar.screenfullF'):$t('navbar.screenfull')"
                  placement="bottom">
        <div class="top-bar__item">
          <i :class="isFullScren?'icon-tuichuquanping':'icon-quanping'"
             @click="handleScreen"></i>
        </div>
      </el-tooltip>
      <img class="top-bar__img"
           :src="userInfo.avatar">
      <el-dropdown>
        <span class="el-dropdown-link">
          {{userInfo.userName}}
          <i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>
            <router-link to="/">{{$t('navbar.dashboard')}}</router-link>
          </el-dropdown-item>
          <el-dropdown-item>
            <router-link to="/info/index">{{$t('navbar.userinfo')}}</router-link>
          </el-dropdown-item>
          <el-dropdown-item @click.native="logout"
                            divided>{{$t('navbar.logOut')}}
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>
<script>
  import {mapGetters, mapState} from "vuex";
  import {fullscreenToggel, listenfullscreen} from "@/util/util";
  import topLock from "./top-lock";
  import topMenu from "./top-menu";
  import topSearch from "./top-search";
  import topTheme from "./top-theme";
  import topLogs from "./top-logs";
  import topColor from "./top-color";
  import topLang from "./top-lang";

  import WebSocketUtil from "@/util/WebSocketUtil.js";
  import {setTheme} from "../../../util/util";
  import router from "../../../router/router";
  import {removeStore} from "../../../util/store";
  import store from "../../../store";

  export default {
    components: {
      topLock,
      topMenu,
      topSearch,
      topTheme,
      topLogs,
      topColor,
      topLang
    },
    name: "top",
    data() {
      return {};
    },
    filters: {},
    created() {
      // 设置默认主题是白色（蓝底）
      setTheme(this.themeName)
    },
    mounted() {
      listenfullscreen(this.setScreen);
    },
    computed: {
      ...mapState({
        showDebug: state => state.common.showDebug,
        showTheme: state => state.common.showTheme,
        showLock: state => state.common.showLock,
        showFullScren: state => state.common.showFullScren,
        showCollapse: state => state.common.showCollapse,
        showSearch: state => state.common.showSearch,
        showMenu: state => state.common.showMenu,
        showColor: state => state.common.showColor,
        showTranslation: state => state.common.showTranslation
      }),
      ...mapGetters([
        "userInfo",
        "isFullScren",
        "tagWel",
        "tagList",
        "isCollapse",
        "tag",
        "logsLen",
        "logsFlag",
        "themeName"
      ]),
      tiAlarm() {
        return this.$store.state.MiniAccident.tiAlarm;
      },
      missedAlarm() {
        return this.$store.state.MiniAccident.missedAlarm;
      }
    },
    methods: {
      handleCommand(command) {
        if (command == 0) {
          this.$router.push({
            path: '/bureau/TICall/TIAlarmRecord',
          });
          this.$store.commit("setTiAlarm", 0);
          WebSocketUtil.initTiAlarm();
        } else if (command == 1) {
          this.$router.push({
            path: '/bureau/VideoCall/MissedConnection',
          });
          this.$store.commit("setMissedAlarm", 0);
          WebSocketUtil.initMissedAlarm();
        }
      },
      handleScreen() {
        fullscreenToggel();
      },
      setCollapse() {
        this.$store.commit("SET_COLLAPSE");
      },
      setScreen() {
        this.$store.commit("SET_FULLSCREN");
      },
      logout() {
        this.$confirm(this.$t("logoutTip"), this.$t("tip"), {
          confirmButtonText: this.$t("submitText"),
          cancelButtonText: this.$t("cancelText"),
          type: "warning"
        }).then(() => {
          this.$store.dispatch("LogOut").then(() => {
            WebSocketUtil.closeWebSocket(true);
            this.$router.push({path: "/login"});
          });
        });
      }
    }
  };
</script>

<style lang="scss" scoped>
  .noti-container {
    margin: 0px 40px 0px 0px;
  }

  .noti-info {
    position: relative;
    cursor: pointer;

    .noti-img {
      width: 32px;
      height: 32px;
    }

    .noti-number {
      width: 20px;
      height: 20px;
      text-align: center;
      line-height: 20px;
      border-radius: 10px;
      position: absolute;
      top: -5px;
      right: -8px;
      background-color: #e32727;
      color: #ffffff;
      font-size: 14px;
    }
  }

  .noti-number-b {
    color: #e32727;
  }
</style>
